import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login/Login.vue'
import System from '../views/System/System.vue'
import Register from '../views/register/Register.vue'
import Business from '../views/Business/Business.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // name: 'Home',
    redirect: '/login',
    // component: System
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  },

  {
    path: '/login',
    name: 'Login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: Login
  },
  
  {
    path: '/system',
    redirect: '/system/companyCustom',
  },

  {
    path: '/system',
    name: 'System',
    component: System,
    beforeEnter: (to, from ,next) => {
      if(localStorage.token) {
        next();
      }else {
        alert('您还未登录');
        next('/login');
      }
    },
    children: [
      {
        path: 'companyCustom',
        name: 'CompanyCustom',
        component: () => import('../views/System/companyCustom/CompanyCustom.vue')
      },
      {
        path: 'addCompanyCustom',
        name: 'addCompanyCustom',
        component: () => import('../views/System/companyCustom/AddCompanyCustom.vue')
      },
      {
        path: 'dealWater',
        name: 'dealWater',
        component: () => import('../views/System/dealWater/dealWater.vue')
      },
      {
        path: 'accounts',
        component: () => import('../views/System/accounts/Accounts.vue')
      },
      {
        path: 'addAccounts',
        component: () => import('../views/System/accounts/AddAccounts.vue')
      },
      
      {
        path: 'business',
        name: 'Business',
        redirect: '/system/business/businessSign',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: Business,
        children: [
          {
            path: 'businessSign',
            component: () => import('../views/Business/BusinessSign.vue')
          },
          {
            path: 'operation',
            beforeEnter: (to, from ,next) => {
              if(localStorage.account) {
                next();
              }else (
                next('/system/business/businessSign')
              )
            },
            component: () => import('../views/Business/Operation.vue')
          }
        ]
      },
    ]
  },
  
  
]

const router = new VueRouter({
  routes
})

export default router
